<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <?php include "../public/substt.php";?>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工资月份</label>
                        <div class="layui-input-block">
                            <input type="text" name="month" id="month"  placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ym">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工资标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" id="title" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>应发合计(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="yingfee" id="yingfee" readonly  placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>应扣合计(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="koufee" id="koufee" readonly  placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>实际应发(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" readonly  placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">计划发放日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="dt" id="dt"  placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>工资明细</span></div>
                        <div>
                            <button type="button" onclick="choose_archive()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">从员工选择</button>
                            <button type="button" onclick="ctrlv_data_open()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">粘贴新增</button>
                            <button type="button" onclick="import_list()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">Excel导入</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_copy_row">复制行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <div style="overflow: auto">
                        <div style="width: 2500px;overflow: hidden">
                            <table class="layui-table" lay-size="sm">
                                <thead>
                                <tr>
                                    <th width="45">序号</th>
                                    <th><text>*</text>姓名</th>
                                    <th><text>*</text>部门</th>
                                    <th><text>*</text>岗位</th>
                                    <th>基本工资</th>
                                    <th>岗位补贴</th>
                                    <th>全勤奖</th>
                                    <th>考核工资</th>
                                    <th>加班工资</th>
                                    <th>奖金</th>
                                    <th>业务提成</th>
                                    <th>其他应发</th>
                                    <th><text>*</text>应发合计</th>
                                    <th>迟到早退</th>
                                    <th>病事假</th>
                                    <th>旷工</th>
                                    <th>社保</th>
                                    <th>公积金</th>
                                    <th>个税</th>
                                    <th>其他应扣</th>
                                    <th><text>*</text>应扣合计</th>
                                    <th><text>*</text>实际应发</th>
                                    <th>备注</th>
                                </tr>
                                </thead>
                                <tbody class="short_table_tbody" id="list_list"></tbody>
                            </table>

                        </div>
                    </div>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>

            <?php include '../public/flowqita.php'?>
            <?php include '../public/upinfo.php'?>
        </div>




    </div>
</form>
<script>
    $("#commentForm").validate({
        rules: {
            month: {required: true},
            title: {required: true},
        },
        messages:{
            month: {required: "请选择"},
            title: {required: "请输入"},
        }
    });


    function choose_archive(){
        openPage('../public/choose_person.php?choose_type=checkbox&page=wage','80%','80%');
    }

    function import_list() {
        openPage('../public/import.php?reveal=wage@importdata', '770px', '490px');
    }

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_add_wage}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                chu_flow_qian(data);


                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td><input type="text" class="layui-input name"></td>';
                listAddStr += '<td><input type="text" class="layui-input deptname"></td>';
                listAddStr += '<td><input type="text" class="layui-input gangname"></td>';
                listAddStr += '<td><input type="number" class="layui-input jiben"></td>';
                listAddStr += '<td><input type="number" class="layui-input gangbu"></td>';
                listAddStr += '<td><input type="number" class="layui-input quanqin"></td>';
                listAddStr += '<td><input type="number" class="layui-input kaohe"></td>';
                listAddStr += '<td><input type="number" class="layui-input jiaban"></td>';
                listAddStr += '<td><input type="number" class="layui-input jiang"></td>';
                listAddStr += '<td><input type="number" class="layui-input yewu"></td>';
                listAddStr += '<td><input type="number" class="layui-input qiying"></td>';
                listAddStr += '<td><input type="number" class="layui-input yingfee"></td>';
                listAddStr += '<td><input type="number" class="layui-input chidao"></td>';
                listAddStr += '<td><input type="number" class="layui-input bing"></td>';
                listAddStr += '<td><input type="number" class="layui-input kuang"></td>';
                listAddStr += '<td><input type="number" class="layui-input shebao"></td>';
                listAddStr += '<td><input type="number" class="layui-input gongjin"></td>';
                listAddStr += '<td><input type="number" class="layui-input geshui"></td>';
                listAddStr += '<td><input type="number" class="layui-input qikou"></td>';
                listAddStr += '<td><input type="number" class="layui-input koufee"></td>';
                listAddStr += '<td><input type="number" class="layui-input money"></td>';
                listAddStr += '<td><input type="text" class="layui-input explain"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr, 1);


                update_refresh_row_func();


                public_upload_file_load('upload_files', res.data.files);
                initParseMoney();
                render_from();
            }
        });



        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();
                if(!validRes){return false;}
            }



            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var name = $(this).find('.name').val();
                    var deptname = $(this).find('.deptname').val();
                    var gangname = $(this).find('.gangname').val();
                    var jiben = $(this).find('.jiben').val();
                    var gangbu = $(this).find('.gangbu').val();
                    var quanqin = $(this).find('.quanqin').val();
                    var kaohe = $(this).find('.kaohe').val();
                    var jiaban = $(this).find('.jiaban').val();
                    var jiang = $(this).find('.jiang').val();
                    var yewu = $(this).find('.yewu').val();
                    var qiying = $(this).find('.qiying').val();
                    var yingfee = $(this).find('.yingfee').val();
                    var chidao = $(this).find('.chidao').val();
                    var bing = $(this).find('.bing').val();
                    var kuang = $(this).find('.kuang').val();
                    var shebao = $(this).find('.shebao').val();
                    var gongjin = $(this).find('.gongjin').val();
                    var geshui = $(this).find('.geshui').val();
                    var qikou = $(this).find('.qikou').val();
                    var koufee = $(this).find('.koufee').val();
                    var money = $(this).find('.money').val();
                    var explain = $(this).find('.explain').val();


                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(!name){
                            throw new Error('第'+index+'行，请输入姓名');
                        }
                        if(!deptname){
                            throw new Error('第'+index+'行，请输入部门');
                        }
                        if(!gangname){
                            throw new Error('第'+index+'行，请输入岗位');
                        }
                        if(!yingfee){
                            throw new Error('第'+index+'行，请输入应发合计');
                        }
                        if(!koufee){
                            throw new Error('第'+index+'行，请输入应扣合计');
                        }
                        if(!money){
                            throw new Error('第'+index+'行，请输入实际应发');
                        }
                    }



                    list.push({
                        name:name,
                        deptname:deptname,
                        gangname:gangname,
                        jiben:jiben,
                        gangbu:gangbu,
                        quanqin:quanqin,
                        kaohe:kaohe,
                        jiaban:jiaban,
                        jiang:jiang,
                        yewu:yewu,
                        qiying:qiying,
                        yingfee:yingfee,
                        chidao:chidao,
                        bing:bing,
                        kuang:kuang,
                        shebao:shebao,
                        gongjin:gongjin,
                        geshui:geshui,
                        qikou:qikou,
                        koufee:koufee,
                        money:money,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;

            data = parseMoney(data);

            data.field.files = public_upload_file_value('upload_files');
            public_flow_submit(data.field, ask_flowdata_add_wage, ask_flowdata_edit_wage, $(this).attr('but'));

            return false;
        });

    });



    $('#list_list').on('input propertychange','.yingfee,.koufee,.money',function () {
        jisuan_money_all();
    });
    function jisuan_money_all() {
        var allyingfee = 0;
        var allkoufee = 0;
        var allmoney = 0;
        $('#list_list tr').each(function (i) {
            var yingfee = parseValidNum($(this).find('.yingfee').val());
            var koufee = parseValidNum($(this).find('.koufee').val());
            var money = parseValidNum($(this).find('.money').val());
            allyingfee = parseFloat(allyingfee) + parseFloat(yingfee);
            allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            allmoney = parseFloat(allmoney) + parseFloat(money);
        });
        $("#yingfee").val(allyingfee);
        $("#koufee").val(allkoufee);
        $("#money").val(allmoney);
        initParseMoney();
    }

    function update_refresh_row_func() {
        render_date();
        render_from();
        jisuan_money_all();

        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }




    var ctrlv_field_name = [
        {field: 'name', name:'姓名'},
        {field: 'deptname', name:'部门'},
        {field: 'gangname', name:'岗位'},
        {field: 'jiben', name:'基本工资',type:'number'},
        {field: 'gangbu', name:'岗位补贴',type:'number'},
        {field: 'quanqin', name:'全勤奖',type:'number'},
        {field: 'kaohe', name:'考核工资',type:'number'},
        {field: 'jiaban', name:'加班工资',type:'number'},
        {field: 'jiang', name:'奖金',type:'number'},
        {field: 'yewu', name:'业务提成',type:'number'},
        {field: 'qiying', name:'其他应发',type:'number'},
        {field: 'yingfee', name:'应发合计',type:'number'},
        {field: 'chidao', name:'迟到早退',type:'number'},
        {field: 'bing', name:'病事假',type:'number'},
        {field: 'kuang', name:'旷工',type:'number'},
        {field: 'shebao', name:'社保',type:'number'},
        {field: 'gongjin', name:'公积金',type:'number'},
        {field: 'geshui', name:'个税',type:'number'},
        {field: 'qikou', name:'其他应扣',type:'number'},
        {field: 'koufee', name:'应扣合计',type:'number'},
        {field: 'money', name:'实际应发',type:'number'},
        {field: 'explain', name:'备注'},
    ];
    function ctrlv_data_show(list) {
        if(list.length > 0){
            var nums = $("#list_list tr").length;
            for (var key in list){
                var str = '';
                nums++;
                str += '<tr>';
                str += '<td style="width: 45px">'+nums+'</td>';
                str += '<td><input type="text" class="layui-input name" value="'+list[key].name+'"></td>';
                str += '<td><input type="text" class="layui-input deptname" value="'+list[key].deptname+'"></td>';
                str += '<td><input type="text" class="layui-input gangname" value="'+list[key].gangname+'"></td>';
                str += '<td><input type="number" class="layui-input jiben" value="'+list[key].jiben+'"></td>';
                str += '<td><input type="number" class="layui-input gangbu" value="'+list[key].gangbu+'"></td>';
                str += '<td><input type="number" class="layui-input quanqin" value="'+list[key].quanqin+'"></td>';
                str += '<td><input type="number" class="layui-input kaohe" value="'+list[key].kaohe+'"></td>';
                str += '<td><input type="number" class="layui-input jiaban" value="'+list[key].jiaban+'"></td>';
                str += '<td><input type="number" class="layui-input jiang" value="'+list[key].jiang+'"></td>';
                str += '<td><input type="number" class="layui-input yewu" value="'+list[key].yewu+'"></td>';
                str += '<td><input type="number" class="layui-input qiying" value="'+list[key].qiying+'"></td>';
                str += '<td><input type="number" class="layui-input yingfee" value="'+list[key].yingfee+'"></td>';
                str += '<td><input type="number" class="layui-input chidao" value="'+list[key].chidao+'"></td>';
                str += '<td><input type="number" class="layui-input bing" value="'+list[key].bing+'"></td>';
                str += '<td><input type="number" class="layui-input kuang" value="'+list[key].kuang+'"></td>';
                str += '<td><input type="number" class="layui-input shebao" value="'+list[key].shebao+'"></td>';
                str += '<td><input type="number" class="layui-input gongjin" value="'+list[key].gongjin+'"></td>';
                str += '<td><input type="number" class="layui-input geshui" value="'+list[key].geshui+'"></td>';
                str += '<td><input type="number" class="layui-input qikou" value="'+list[key].qikou+'"></td>';
                str += '<td><input type="number" class="layui-input koufee" value="'+list[key].koufee+'"></td>';
                str += '<td><input type="number" class="layui-input money" value="'+list[key].money+'"></td>';
                str += '<td><input type="text" class="layui-input explain" value="'+list[key].explain+'"></td>';
                str += '</tr>';
                $("#list_list").append(str);
            }
        }
        update_refresh_row_func();
        render_date();
        render_from();
    }

</script>
</body>
</html>
